<?php
/**
 * 金融服务类
 */
namespace app\index\service;
use Config;
use Cache;
use think\Db;

class Finance
{
	/**
	 * 金融主页
	 */
	public function index()
	{
      return '金融主页';
	}

	/**
	 * 个人借贷情况
	 * 个人基本资料
	 */
	public function getFininfo(){

	}


	/**
	 * 个人还贷情况
	 */
	

	/**
	 * 借贷申请
	 */
	public function saveFinInfo($param=[]){
		$model = new \app\index\model\Apply;
		// 启动事务
		Db::startTrans();
		//申请人贷款进度
		try{
			if(empty($param['member_id'])){
				Db::rollback();
				exception('用户ID不能为空');
			}
			$is_verfiy = $model::where('is_verfiy=1')->get(['member_id'=>$param['member_id']])->value('is_verfiy')??0;
			if($is_verfiy>0){
				$code = 1;
				$msg = '你已有正在审核中，请耐心等待';
			}else{
				if(empty($param['id'])){
					$param['create_time'] = $param['update_time'] = time();
					$model->allowField(true)->save($param)??0;
					$code = 1;
					$msg = '申请成功,等待系统审核';
				}else{
					$param['update_time'] = time();//修改
					$model->allowField(true)->save($param,['id'=>$param['id']])??0;
				}
			}	
		    // 提交事务
		    Db::commit();
		    return ['status'=>$code,'msg'=>$msg];    
		} catch (\Exception $e){
		    // 回滚事务
		    Db::rollback();
		    return ['status'=>0,'msg'=>$e->getMessage()];
		}
	}
}